package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.RoomInfo;
import com.atguigu.lease.web.admin.dto.RoomInfoSearchDto;
import com.atguigu.lease.web.admin.dto.RoomInfoSubmitDto;
import com.atguigu.lease.web.admin.service.RoomInfoService;
import com.atguigu.lease.web.admin.vo.RoomInfoDetailVo;
import com.atguigu.lease.web.admin.vo.RoomInfoVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/admin/room")
@Tag(name = "房间管理模块")
public class RoomInfoController {
    @Resource
    RoomInfoService roomInfoService;
    //listBasicByApartmentId?id=10
    @Operation(summary = "根据公寓id查询房间列表")
    @GetMapping("listBasicByApartmentId")
    public Result<List<RoomInfo>> listBasicByApartmentId(@RequestParam("id")Long apartmentId){

        return Result.ok(roomInfoService.listRoomInfoByApartmentId(apartmentId));
    }


    @Operation(summary = "根据id查询房间详情")
    @GetMapping("getDetailById")
    public Result<RoomInfoDetailVo> getDetailById(@RequestParam("id")Long id){
        return Result.ok(roomInfoService.getDetailById(id));
    }
    @Operation(summary = "更新房间发布状态")
    @PostMapping("updateReleaseStatusById")
    public Result updateReleaseStatusById(@RequestParam("id")Long id ,
                                          @RequestParam("status")Integer status){
        return Result.build(roomInfoService.update(Wrappers.lambdaUpdate(RoomInfo.class)
                .eq(RoomInfo::getId , id)
                .set(RoomInfo::getIsRelease , status)
                .set(RoomInfo::getUpdateTime, new Date())));
    }
    //removeById?id=15
    @Operation(summary = "删除房间")
    @DeleteMapping("removeById")
    public Result removeById(@RequestParam("id")Long id){
        return Result.build(roomInfoService.removeRoomInfoById(id));
    }
    @Operation(summary = "条件查询分页数据")
    @GetMapping("pageItem")
    public Result<Page<RoomInfoVo>> pageItem(RoomInfoSearchDto searchDto){
        return Result.ok(roomInfoService.pageItem(searchDto));
    }
    @Operation(summary = "新增或更新房间")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoomInfoSubmitDto submitDto){
        return Result.build(roomInfoService.saveOrUpdateRoomInfoSubmitDto(submitDto));
    }
}
